package com.epalmpay.controller.channel.activity;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.epalmpay.dto.activity.*;
import com.epalmpay.dto.system.PageDTO;
import com.epalmpay.entity.*;
import com.epalmpay.enumdef.ActivityEnum;
import com.epalmpay.util.Tools;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.memberGrade.MemberGradeOutDTO;
import com.epalmpay.service.activity.IActivityBaseService;
import com.epalmpay.service.activity.IActivityCouponService;
import com.epalmpay.service.activity.IActivityRedPackageService;
import com.epalmpay.service.activity.IActivityRoutineRegisterService;
import com.epalmpay.service.activity.IActivityRoutineRuleService;
import com.epalmpay.service.activity.IActivityRoutineService;
import com.epalmpay.service.activity.IActivityRoutinesignedService;
import com.epalmpay.service.member.IMemberGradeService;
import com.epalmpay.util.PropertyCopyUtil;

/**
 * Created by Administrator on 2017/5/22.
 */
@Controller
@RequestMapping(value="/channel/activity")
public class RoutineController extends BaseController {
    @Resource
    private IActivityRoutineService activityRoutineService;
    @Resource
    private IActivityCouponService activityCouponService;
    @Resource
    private IActivityRedPackageService activityRedPackageService;
    @Resource
    private IActivityRoutineRuleService activityRoutineRuleService;

    @Resource
    private IMemberGradeService memberGradeService;

    @Resource
    private IActivityBaseService activityBaseService;

    @Resource
    private IActivityRoutinesignedService activityRoutinesignedService;


    @Resource IActivityRoutineRegisterService activityRoutineRegisterService;

    //通过groupid id,获取当前的活动的详细信息
    @RequestMapping(value="/routineList")
    @ResponseBody
    public RoutineOutDTO GetRoutineList(@RequestBody RoutineInDTO routineInDTO){
        RoutineOutDTO routineOutDTO=new RoutineOutDTO();
        try {

            //活动信息
            ActivityRoutine activityRoutine=new ActivityRoutine();
            activityRoutine.setGroupId(routineInDTO.getGroupId());
            activityRoutine.setLoginId(routineInDTO.getLoginId());
//只检测数据，初始化数据，
            activityRoutineService.InitialRoutineActivity(activityRoutine);
            routineOutDTO.setErrorCode("0000");//强制成功哈哈
//            获取固定活动主页所有的数据，固定活动默认acitityid (31---37)


            MemberBirthdayInDTO memberBirthdayInDTO=new MemberBirthdayInDTO();
            memberBirthdayInDTO.setGroupId(routineInDTO.getGroupId());
            memberBirthdayInDTO.setPurposeType(1);
            memberBirthdayInDTO.setUserId(routineInDTO.getLoginId());

            memberBirthdayInDTO.setId(activityRoutine.getGroupId()*100+31l);
            MemberBirthdayOutDTO memberBirthdayOutDTO=GetRoutineDetails(memberBirthdayInDTO);
            routineOutDTO.setMemberBirthdayData(memberBirthdayOutDTO);


            MemberBirthdayInDTO upgrade=new MemberBirthdayInDTO();
            upgrade.setGroupId(routineInDTO.getGroupId());
            upgrade.setPurposeType(1);
            upgrade.setUserId(routineInDTO.getLoginId());
            upgrade.setId(activityRoutine.getGroupId()*100+32l);
            MemberBirthdayOutDTO upgradeResult=GetRoutineDetails(upgrade);
            routineOutDTO.setRoutineTimeData(upgradeResult);

            MemberBirthdayInDTO routineTime=new MemberBirthdayInDTO();
            routineTime.setGroupId(routineInDTO.getGroupId());
            routineTime.setPurposeType(1);
            routineTime.setUserId(routineInDTO.getLoginId());
            routineTime.setId(activityRoutine.getGroupId()*100+33l);
            MemberBirthdayOutDTO routineTimeResult=GetRoutineDetails(routineTime);
            routineOutDTO.setUpgradeData(routineTimeResult);

            MemberBirthdayInDTO lifeCycle=new MemberBirthdayInDTO();
            lifeCycle.setGroupId(routineInDTO.getGroupId());
            lifeCycle.setPurposeType(1);
            lifeCycle.setUserId(routineInDTO.getLoginId());
            lifeCycle.setId(activityRoutine.getGroupId()*100+34l);
            MemberBirthdayOutDTO lifeCycleResult=GetRoutineDetails(lifeCycle);
            routineOutDTO.setLifeCycleData(lifeCycleResult);

            MemberBirthdayInDTO shareRedPacket=new MemberBirthdayInDTO();
            shareRedPacket.setGroupId(routineInDTO.getGroupId());
            shareRedPacket.setPurposeType(1);
            shareRedPacket.setUserId(routineInDTO.getLoginId());
            shareRedPacket.setId(activityRoutine.getGroupId()*100+37l);
            MemberBirthdayOutDTO shareRedPacketResult=GetRoutineDetails(shareRedPacket);
            routineOutDTO.setShareRedPacketData(shareRedPacketResult);

            ActivityRoutinesignedInDTO memberSigned=new ActivityRoutinesignedInDTO();
            memberSigned.setGroupId(routineInDTO.getGroupId());
            memberSigned.setPurposeType(1);
            memberSigned.setActivityId(activityRoutine.getGroupId()*100+35l);
            ActivityRoutinesignedOutDTO activityRoutinesignedOutDTO=GetSignActivityDetails(memberSigned);
            routineOutDTO.setMemberSignedData(activityRoutinesignedOutDTO);


            ActivityRoutineRegister memberRegister=new ActivityRoutineRegister();
            memberRegister.setGroupId(routineInDTO.getGroupId());
            memberRegister.setPurposeType(1);
            memberRegister.setActivityId(activityRoutine.getGroupId()*100+36l);
            ActivityRoutineRegisterOutDTO activityRoutineRegisterOutDTO=GetRegisterActivityDetails(memberRegister);
            routineOutDTO.setMemberRegisterData(activityRoutineRegisterOutDTO);




            return routineOutDTO;
        } catch (ApplicationException ae) {
            routineOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            routineOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return routineOutDTO;



    }
//通过groupid id,获取当前的活动的详细信息
    @RequestMapping(value="/getRoutineDetails")
    @ResponseBody
    public MemberBirthdayOutDTO GetRoutineDetails(MemberBirthdayInDTO memberBirthdayInDTO){
        MemberBirthdayOutDTO memberBirthdayOutDTO=new MemberBirthdayOutDTO();
        try {

 //活动信息
            ActivityRoutine  activityRoutine=activityRoutineService.GetRoutineWithGroupIdAndActivityId(memberBirthdayInDTO);
            PropertyCopyUtil.copyProperties(activityRoutine,memberBirthdayOutDTO);



//            if (activityRoutine.getActivityType()>4){
//                memberBirthdayOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
//                return memberBirthdayOutDTO;
//            }
//            会员等级信息
            List<ActivityRoutineRuleOutDTO> activityRoutineRuleList=activityRoutineRuleService.GetRoutineActivityMemberGradeList(memberBirthdayInDTO.getId(),memberBirthdayInDTO.getGroupId());
            memberBirthdayOutDTO.setRoutineActivityMemberGradeList(activityRoutineRuleList);


//获取会员等级固定数据列表
            com.epalmpay.dto.memberGrade.MemberGradeInDTO memberGradeInDTO=new com.epalmpay.dto.memberGrade.MemberGradeInDTO();
            memberGradeInDTO.setGroupId(memberBirthdayInDTO.getGroupId());
            List<MemberGradeOutDTO> memberOutList=memberGradeService.listMembers(memberGradeInDTO);

//获取会员等级大小，给前台用
            memberBirthdayOutDTO.setMemberGradeListSize(memberOutList.size());

            if(((activityRoutineRuleList.size()-1)!=memberOutList.size())&&(activityRoutine.getActivityType()!=4)){
//                删除符合数据的数据，重新创造
//                if (activityRoutineRuleList.size()>0) {
                    activityRoutineRuleService.DeleteRoutineActivityMemberGradeList(memberBirthdayInDTO.getId());
//                }


                for (int i = 0; i <memberOutList.size() ; i++) {

                    ActivityRoutineRule activityRoutineRule=new ActivityRoutineRule();
                    Date date=new Date();
                    activityRoutineRule.setGmtCreate(date);

                    activityRoutineRule.setGmtModified(date);
                    activityRoutineRule.setActivityId(memberBirthdayInDTO.getId());
                    activityRoutineRule.setSendType(ActivityEnum.ActivitySendType.NoSend.getType());
                    activityRoutineRule.setRedpackageId(1L);
                    activityRoutineRule.setCouponId(1l);
                    activityRoutineRule.setLifecycleType(1);
                    activityRoutineRule.setUndoDays(null);

//                    这句不能删
                    MemberGradeOutDTO memberGradeOutDTO=new MemberGradeOutDTO();
                    PropertyCopyUtil.copyProperties(memberOutList.get(i),memberGradeOutDTO);

                    activityRoutineRule.setMemberGrade(memberGradeOutDTO.getId());

                    activityRoutineRuleService.InsetRoutineActivityMemberGrade(activityRoutineRule);
                }

                ActivityRoutineRule activityRoutineRule=new ActivityRoutineRule();
                Date date=new Date();
                activityRoutineRule.setGmtCreate(date);

                activityRoutineRule.setGmtModified(date);
                activityRoutineRule.setActivityId(memberBirthdayInDTO.getId());
                activityRoutineRule.setSendType(ActivityEnum.ActivitySendType.NoSend.getType());
                activityRoutineRule.setRedpackageId(1l);
                activityRoutineRule.setCouponId(1l);
                activityRoutineRule.setLifecycleType(1);
                activityRoutineRule.setUndoDays(null);
//                    这句不能删
                activityRoutineRule.setMemberGrade(null);

                activityRoutineRuleService.InsetRoutineActivityMemberGrade(activityRoutineRule);

                //            会员等级信息
                List<ActivityRoutineRuleOutDTO> activityRoutineRuleList1=activityRoutineRuleService.GetRoutineActivityMemberGradeList(memberBirthdayInDTO.getId(),memberBirthdayInDTO.getGroupId());
                memberBirthdayOutDTO.setRoutineActivityMemberGradeList(activityRoutineRuleList1);


            }

            if (activityRoutine.getActivityType()==4){

                if((activityRoutineRuleList.size()-10)!=memberOutList.size()*10) {
//                删除符合数据的数据，重新创造
//                    if (activityRoutineRuleList.size() > 0) {
                        activityRoutineRuleService.DeleteRoutineActivityMemberGradeList(memberBirthdayInDTO.getId());
//                    }
                    for(int j=0;j<5;j++){
                        for (int i = 0; i <memberOutList.size() ; i++) {

                            ActivityRoutineRule activityRoutineRule=new ActivityRoutineRule();
                            Date date=new Date();
                            activityRoutineRule.setGmtCreate(date);

                            activityRoutineRule.setGmtModified(date);
                            activityRoutineRule.setActivityId(memberBirthdayInDTO.getId());
                            activityRoutineRule.setSendType(ActivityEnum.ActivitySendType.NoSend.getType());
                            activityRoutineRule.setRedpackageId(1L);
                            activityRoutineRule.setCouponId(1l);
                            activityRoutineRule.setLifecycleType(1);
                            activityRoutineRule.setUndoDays(null);

//                    这句不能删
                            MemberGradeOutDTO memberGradeOutDTO=new MemberGradeOutDTO();
                            PropertyCopyUtil.copyProperties(memberOutList.get(i),memberGradeOutDTO);

                            activityRoutineRule.setMemberGrade(memberGradeOutDTO.getId());

                            activityRoutineRuleService.InsetRoutineActivityMemberGrade(activityRoutineRule);
                        }

                        ActivityRoutineRule activityRoutineRule=new ActivityRoutineRule();
                        Date date=new Date();
                        activityRoutineRule.setGmtCreate(date);

                        activityRoutineRule.setGmtModified(date);
                        activityRoutineRule.setActivityId(memberBirthdayInDTO.getId());
                        activityRoutineRule.setSendType(ActivityEnum.ActivitySendType.NoSend.getType());
                        activityRoutineRule.setRedpackageId(1l);
                        activityRoutineRule.setCouponId(1l);
                        activityRoutineRule.setLifecycleType(1);
                        activityRoutineRule.setUndoDays(null);
//                    这句不能删
                        activityRoutineRule.setMemberGrade(null);

                        activityRoutineRuleService.InsetRoutineActivityMemberGrade(activityRoutineRule);

                    }


//                轮训两次

                    for(int j=0;j<5;j++) {
                        for (int i = 0; i <memberOutList.size() ; i++) {

                            ActivityRoutineRule activityRoutineRule_1=new ActivityRoutineRule();
                            Date date_1=new Date();
                            activityRoutineRule_1.setGmtCreate(date_1);

                            activityRoutineRule_1.setGmtModified(new Date());
                            activityRoutineRule_1.setActivityId(memberBirthdayInDTO.getId());
                            activityRoutineRule_1.setSendType(ActivityEnum.ActivitySendType.NoSend.getType());
                            activityRoutineRule_1.setRedpackageId(1L);
                            activityRoutineRule_1.setCouponId(1l);
                            activityRoutineRule_1.setLifecycleType(2);
                            activityRoutineRule_1.setUndoDays(null);

//                    这句不能删
                            MemberGradeOutDTO memberGradeOutDTO=new MemberGradeOutDTO();
                            PropertyCopyUtil.copyProperties(memberOutList.get(i),memberGradeOutDTO);

                            activityRoutineRule_1.setMemberGrade(memberGradeOutDTO.getId());

                            activityRoutineRuleService.InsetRoutineActivityMemberGrade(activityRoutineRule_1);
                        }

                        ActivityRoutineRule activityRoutineRule_1=new ActivityRoutineRule();
                        Date date_1=new Date();
                        activityRoutineRule_1.setGmtCreate(date_1);

                        activityRoutineRule_1.setGmtModified(new Date());
                        activityRoutineRule_1.setActivityId(memberBirthdayInDTO.getId());
                        activityRoutineRule_1.setSendType(ActivityEnum.ActivitySendType.NoSend.getType());
                        activityRoutineRule_1.setRedpackageId(1l);
                        activityRoutineRule_1.setCouponId(1l);
                        activityRoutineRule_1.setLifecycleType(2);
                        activityRoutineRule_1.setUndoDays(null);
//                    这句不能删
                        activityRoutineRule_1.setMemberGrade(null);

                        activityRoutineRuleService.InsetRoutineActivityMemberGrade(activityRoutineRule_1);
                    }
                    //            会员等级信息
                    List<ActivityRoutineRuleOutDTO> activityRoutineRuleList2=activityRoutineRuleService.GetRoutineActivityMemberGradeList(memberBirthdayInDTO.getId(),memberBirthdayInDTO.getGroupId());
                    memberBirthdayOutDTO.setRoutineActivityMemberGradeList(activityRoutineRuleList2);
                }


            }




//获取优惠券信息
            CouponInDTO couponInDTO=new CouponInDTO();
            couponInDTO.setGroupId(memberBirthdayInDTO.getGroupId());
            couponInDTO.setPurposeType(memberBirthdayInDTO.getPurposeType());
            List<CouponOutDTO> couponOutDTOList = activityCouponService.GetSpecialActivityCouponList(couponInDTO);
            memberBirthdayOutDTO.setCouponOutDTOList(couponOutDTOList);
//红包
            RedPackageInDTO redPackageInDTO=new RedPackageInDTO();
            redPackageInDTO.setGroupId(memberBirthdayInDTO.getGroupId());
            redPackageInDTO.setPurposeType(memberBirthdayInDTO.getPurposeType());
            List<RedPackageOutDTO> redPackageOutDTOList = activityRedPackageService.GetSpecialRedpackageList(redPackageInDTO);
            memberBirthdayOutDTO.setRedPackageOutDTOList(redPackageOutDTOList);




            memberBirthdayOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return memberBirthdayOutDTO;
        } catch (ApplicationException ae) {
            memberBirthdayOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberBirthdayOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return memberBirthdayOutDTO;

    }


    @RequestMapping(value="/updateRoutineDetails")
    @ResponseBody
    public MemberBirthdayOutDTO UpdateRoutineDetails(@RequestBody MemberBirthdayInDTO memberBirthdayInDTO){
        MemberBirthdayOutDTO memberBirthdayOutDTO=new MemberBirthdayOutDTO();
        try {

            ActivityRoutine activityRoutine =new ActivityRoutine();
            PropertyCopyUtil.copyProperties(memberBirthdayInDTO,activityRoutine);
            activityRoutine.setActivityId(memberBirthdayInDTO.getId());
            activityRoutine.setGmtModified(new Date());
            activityRoutine.setSendTime(memberBirthdayInDTO.getGiftTimeType());


            activityRoutine.setFixedDate(memberBirthdayInDTO.getFixedDate());
            activityRoutine.setIsLoginManage(memberBirthdayInDTO.getHasLoginManage());
            activityRoutine.setIsConsumeManage(memberBirthdayInDTO.getHasConsumeManage());
            int  status=activityRoutineService.UpdateRoutineWithGroupIdAndActivityId(activityRoutine);


            ActivityRoutine activityRoutine_2=activityRoutineService.GetRoutineWithGroupIdAndActivityId(memberBirthdayInDTO);
            if (activityRoutine_2.getMemberRiented()==1){
                activityRoutineRuleService.UpdateRoutineActivityMemberGradeListSendType(activityRoutine_2.getActivityId()+"","1");
            }else{
                activityRoutineRuleService.UpdateRoutineActivityMemberGradeListSendType(activityRoutine_2.getActivityId()+"","2");
            }

            ActivityBase activityBase=new ActivityBase();
            PropertyCopyUtil.copyProperties(memberBirthdayInDTO,activityBase);
            activityBase.setGmtModified(new Date());
            activityBase.setActivityId(memberBirthdayInDTO.getId());
            activityBase.setMaxAmount(memberBirthdayInDTO.getMaxAmount());
            activityBaseService.UpdateActivityBaseByActivityId(activityBase);

            //会员等级信息

            //            会员等级信息
//            ActivityRoutineRule


            for (MemberGradeInDTO memberGradeInDTO: memberBirthdayInDTO.getMemberGradeList()
                    ) {
                ActivityRoutineRule activityRoutineRule=new ActivityRoutineRule();
                activityRoutineRule.setCouponId(memberGradeInDTO.getCouponId());
                activityRoutineRule.setRedpackageId(memberGradeInDTO.getRedPackageId());
                activityRoutineRule.setUndoDays(memberGradeInDTO.getUndoDays());
                activityRoutineRule.setId(memberGradeInDTO.getId());
                activityRoutineRule.setSendType(memberGradeInDTO.getSendType());
                activityRoutineRule.setGmtModified(new Date());
                activityRoutineRule.setIntegral(memberGradeInDTO.getIntegral());
               int queryStatus= activityRoutineRuleService.UpdateRoutineActivityMemberGradeList(activityRoutineRule);

            }





            memberBirthdayOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return memberBirthdayOutDTO;
        } catch (ApplicationException ae) {
            memberBirthdayOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberBirthdayOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return memberBirthdayOutDTO;
    }





    //通过groupid id,获取当前的活动的详细信息
    @RequestMapping(value="/getSignActivityDetails")
    @ResponseBody
    public ActivityRoutinesignedOutDTO GetSignActivityDetails(ActivityRoutinesignedInDTO activityRoutinesignedInDTO){
        ActivityRoutinesignedOutDTO activityRoutinesignedOutDTO=new ActivityRoutinesignedOutDTO();
        try {

            //活动信息
            ActivityRoutinesigned activityRoutinesigned=activityRoutinesignedService.QueryActivityByActivityId(activityRoutinesignedInDTO.getActivityId());
            if (activityRoutinesigned!=null){
                PropertyCopyUtil.copyProperties(activityRoutinesigned,activityRoutinesignedOutDTO);
            }


//获取优惠券信息
            CouponInDTO couponInDTO=new CouponInDTO();
            couponInDTO.setGroupId(activityRoutinesignedInDTO.getGroupId());
            couponInDTO.setPurposeType(activityRoutinesignedInDTO.getPurposeType());
            List<CouponOutDTO> couponOutDTOList = activityCouponService.GetSpecialActivityCouponList(couponInDTO);
            activityRoutinesignedOutDTO.setCouponOutDTOList(couponOutDTOList);
//红包
            RedPackageInDTO redPackageInDTO=new RedPackageInDTO();
            redPackageInDTO.setGroupId(activityRoutinesignedInDTO.getGroupId());
            redPackageInDTO.setPurposeType(activityRoutinesignedInDTO.getPurposeType());
            List<RedPackageOutDTO> redPackageOutDTOList = activityRedPackageService.GetSpecialRedpackageList(redPackageInDTO);
            activityRoutinesignedOutDTO.setRedPackageOutDTOList(redPackageOutDTOList);




            activityRoutinesignedOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return activityRoutinesignedOutDTO;
        } catch (ApplicationException ae) {
            activityRoutinesignedOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            activityRoutinesignedOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return activityRoutinesignedOutDTO;

    }


    @RequestMapping(value="/updateSignActivityDetails")
    @ResponseBody
    public ActivityRoutinesignedOutDTO UpdateSignActivityDetails( ActivityRoutinesignedInDTO activityRoutinesignedInDTO){
        ActivityRoutinesignedOutDTO activityRoutinesignedOutDTO=new ActivityRoutinesignedOutDTO();
        try {

            ActivityRoutinesigned activityRoutinesigned =new ActivityRoutinesigned();

            PropertyCopyUtil.copyProperties(activityRoutinesignedInDTO,activityRoutinesigned);

            activityRoutinesigned.setGmtModified(new Date());


            int  status=activityRoutinesignedService.UpdateActivityByActivityId(activityRoutinesigned);

            if (!(status>0)){
                activityRoutinesignedOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            }

            ActivityBase activityBase=new ActivityBase();
//            PropertyCopyUtil.copyProperties(activityRoutinesignedInDTO,activityBase);
            activityBase.setGmtModified(new Date());
            activityBase.setActivityId(activityRoutinesignedInDTO.getActivityId());
            activityBase.setMaxAmount(activityRoutinesignedInDTO.getMaxAmount());
            int status_2=activityBaseService.UpdateActivityBaseByActivityId(activityBase);

            if (!(status_2>0)){
                activityRoutinesignedOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            }

            activityRoutinesignedOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return activityRoutinesignedOutDTO;
        } catch (ApplicationException ae) {
            activityRoutinesignedOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            activityRoutinesignedOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return activityRoutinesignedOutDTO;
    }





    //通过groupid id,获取当前的活动的详细信息
    @RequestMapping(value="/getRegisterActivityDetails")
    @ResponseBody
    public ActivityRoutineRegisterOutDTO GetRegisterActivityDetails(ActivityRoutineRegister activityRoutineRegister){
        ActivityRoutineRegisterOutDTO activityRoutineRegisterOutDTO=new ActivityRoutineRegisterOutDTO();
        try {

            //活动信息
            ActivityRoutineRegister activityRoutinesigned=activityRoutineRegisterService.QueryActivityByActivityId(activityRoutineRegister.getActivityId());
            if (activityRoutinesigned!=null){
                PropertyCopyUtil.copyProperties(activityRoutinesigned,activityRoutineRegisterOutDTO);
            }


//获取优惠券信息
            CouponInDTO couponInDTO=new CouponInDTO();
            couponInDTO.setGroupId(activityRoutineRegister.getGroupId());
            couponInDTO.setPurposeType(activityRoutineRegister.getPurposeType());
            List<CouponOutDTO> couponOutDTOList = activityCouponService.GetSpecialActivityCouponList(couponInDTO);
            activityRoutineRegisterOutDTO.setCouponOutDTOList(couponOutDTOList);
//红包
            RedPackageInDTO redPackageInDTO=new RedPackageInDTO();
            redPackageInDTO.setGroupId(activityRoutineRegister.getGroupId());
            redPackageInDTO.setPurposeType(activityRoutineRegister.getPurposeType());
            List<RedPackageOutDTO> redPackageOutDTOList = activityRedPackageService.GetSpecialRedpackageList(redPackageInDTO);
            activityRoutineRegisterOutDTO.setRedPackageOutDTOList(redPackageOutDTOList);




            activityRoutineRegisterOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return activityRoutineRegisterOutDTO;
        } catch (ApplicationException ae) {
            activityRoutineRegisterOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            activityRoutineRegisterOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return activityRoutineRegisterOutDTO;

    }


    @RequestMapping(value="/updateRegisterActivityDetails")
    @ResponseBody
    public ActivityRoutineRegisterOutDTO UpdateRegisterActivityDetails( ActivityRoutineRegister activityRoutineRegister){
        ActivityRoutineRegisterOutDTO activityRoutineRegisterOutDTO=new ActivityRoutineRegisterOutDTO();
        try {



            activityRoutineRegister.setGmtModified(new Date());


            int  status=activityRoutineRegisterService.UpdateActivityByActivityId(activityRoutineRegister);

            if (!(status>0)){
                activityRoutineRegisterOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            }



            activityRoutineRegisterOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return activityRoutineRegisterOutDTO;
        } catch (ApplicationException ae) {
            activityRoutineRegisterOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            activityRoutineRegisterOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return activityRoutineRegisterOutDTO;
    }

    @RequestMapping(value="/updateActivityStatus")
    @ResponseBody
    public MemberBirthdayOutDTO UpdateActivityStatus( ActivityBase activityBase){
        MemberBirthdayOutDTO memberBirthdayOutDTO=new MemberBirthdayOutDTO();
        try {



            memberBirthdayOutDTO.setGmtModified(new Date());


            int  status=activityBaseService.UpdateActivityBaseByActivityId(activityBase);


            if (!(status>0)){
                memberBirthdayOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            }



            memberBirthdayOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return memberBirthdayOutDTO;
        } catch (ApplicationException ae) {
            memberBirthdayOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            memberBirthdayOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return memberBirthdayOutDTO;
    }

    @RequestMapping(value="/getActivityDataList")
    @ResponseBody
    public ActivityRoutineListOutDTO GetActivityDataList( ActivityRoutineInDTO activityRoutineInDTO,PageDTO pageDTO){
        ActivityRoutineListOutDTO activityRoutineListOutDTO=new ActivityRoutineListOutDTO();

        try {
            Page page= Tools.pageEmtity(pageDTO);
            if(activityRoutineInDTO.getIsReload()){
                activityRoutineListOutDTO =activityRoutineService.GetActivityRoutineList(activityRoutineInDTO,page);

            }
//获取优惠券信息
            CouponInDTO couponInDTO=new CouponInDTO();
            couponInDTO.setGroupId(activityRoutineInDTO.getGroupId());
            couponInDTO.setPurposeType(1);
            List<CouponOutDTO> couponOutDTOList = activityCouponService.GetSpecialActivityCouponList(couponInDTO);
            activityRoutineListOutDTO.setCouponOutDTOList(couponOutDTOList);
//红包
            RedPackageInDTO redPackageInDTO=new RedPackageInDTO();
            redPackageInDTO.setGroupId(activityRoutineInDTO.getGroupId());
            redPackageInDTO.setPurposeType(1);
            List<RedPackageOutDTO> redPackageOutDTOList = activityRedPackageService.GetSpecialRedpackageList(redPackageInDTO);
            activityRoutineListOutDTO.setRedPackageOutDTOList(redPackageOutDTOList);


            activityRoutineListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
            return activityRoutineListOutDTO;
        } catch (ApplicationException ae) {
            activityRoutineListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
            ae.printStackTrace();
        }
        catch (Exception e) {
            activityRoutineListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
            e.printStackTrace();
        }
        return activityRoutineListOutDTO;
    }
}
